package cn.platform.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import cn.platform.request.IdentifyRequest;
import cn.platform.response.AResponse;
import cn.platform.service.IdentifyService;
import cn.platform.util.identify.SessionToken;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin(maxAge = 3600) //允许跨域请求
@Controller
@RequestMapping("/api/user")
@Slf4j
public class IdentifyController {

    @Resource
    private IdentifyService identifyService;

    /**
     * 登录验证
     */
    @PostMapping("/tryLogin")
    @ResponseBody
    public AResponse tryLogin(@RequestBody IdentifyRequest identifyRequest) {
        log.info("登陆验证：{}", identifyRequest.getUsername());
        return identifyService.tryLogin(identifyRequest);
    }

    /**
     * 会话令牌有效性验证
     */
    @RequestMapping("/checkToken")
    @ResponseBody
    public AResponse checkToken() {
        return identifyService.checkToken();
    }

    /**
     * 登出
     */
    @RequestMapping("/logout")
    @ResponseBody
    public AResponse logout() {
        return identifyService.logout();
    }
}
